package com.scau.clothes.stock.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scau.clothes.core.util.CheckObjectIsNullUtils;
import com.scau.clothes.stock.mapper.SizeMapper;
import com.scau.clothes.stock.model.entity.Color;
import com.scau.clothes.stock.model.entity.Size;
import com.scau.clothes.stock.service.SizeService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SizeServiceImpl extends ServiceImpl<SizeMapper, Size> implements SizeService {

    @Resource
    private SizeMapper sizeMapper;
    private CheckObjectIsNullUtils checkObjectIsNullUtils = new CheckObjectIsNullUtils();

    @Override
    public int insertSize(Size size) {
        return sizeMapper.insert(size);
    }

    @Override
    public int updateSize(Size size) {
        size.setIsDelete(0);
        return sizeMapper.updateById(size);
    }

    @Override
    public int deleteSize(Size size) {
        size.setIsDelete(1);
        return sizeMapper.updateById(size);
    }

    @Override
    public List<Size> listAllSize(Size size) {
        QueryWrapper<Size> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne("is_delete", 1);
        if (!checkObjectIsNullUtils.objCheckIsNull(size)){
            if (size.getSizeId()!=null)
                queryWrapper.eq("size_id", size.getSizeId());
            if (size.getSizeName() != null)
                queryWrapper.like("size_name", size.getSizeName());
        }
        List<Size> list = list(queryWrapper);
        return list;
    }
}
